﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using 数据函数库;

namespace 温室大棚
{
    public partial class Form历史数据 : Form
    {
        public Form历史数据()
        {
            InitializeComponent();
        }

        private void Form历史数据_Load(object sender, EventArgs e)
        {
            WFNetLib.MyControls.ToolStripDateTimePicker startDateTimePicker = new WFNetLib.MyControls.ToolStripDateTimePicker(DateTime.Now.AddDays(-7));
            startDateTimePicker.Control.Width = 110;
            toolStrip1.Items.Insert(7, startDateTimePicker);
            WFNetLib.MyControls.ToolStripDateTimePicker endDateTimePicker = new WFNetLib.MyControls.ToolStripDateTimePicker(DateTime.Now);
            endDateTimePicker.Control.Width = 110;
            toolStrip1.Items.Insert(9, endDateTimePicker);
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("SELECT   IP, GreenhouseAddr AS 大棚号, NoteNum AS 节点号, 空气温度1, 空气温度2, 空气温度3, 空气湿度1, 空气湿度2, 空气湿度3, 光照1, 光照2, 光照3, 土壤盐分1, 土壤盐分2, 土壤盐分3, 土壤温度1, 土壤温度2, 土壤温度3, 土壤湿度1, 土壤湿度2, 土壤湿度3, 二氧化碳1, 二氧化碳2, 二氧化碳3, Time AS 时间 FROM 实时数据 where ");
            if(toolStripTextBox1.Text!="")
            {
                sql.Append("(IP = '");
                sql.Append(toolStripTextBox1.Text);
                sql.Append("') AND ");
            }
            if(toolStripTextBox2.Text!="")
            {
                sql.Append("(GreenhouseAddr =");
                sql.Append(toolStripTextBox2.Text);
                sql.Append(") AND ");
            }
            if(toolStripTextBox3.Text!="")
            {
                sql.Append("(NoteNum =");
                sql.Append(toolStripTextBox3.Text);
                sql.Append(") AND ");
            }
            DateTime start = ((WFNetLib.MyControls.ToolStripDateTimePicker)toolStrip1.Items[7]).Control.Value;
            DateTime end = ((WFNetLib.MyControls.ToolStripDateTimePicker)toolStrip1.Items[9]).Control.Value;
            start = start.Date;
            end = end.Date.AddDays(1);
            sql.Append("(Time between '");
            sql.Append(start.ToString("yyyy-MM-dd 00:00:00"));
            sql.Append("' and '");
            sql.Append(end.ToString("yyyy-MM-dd 00:00:00"));
            sql.Append("')");
            DataTable dt = WFNetLib.ADO.SQLServerOP.DataTableSQL(sql.ToString());
            dataGridView1.DataSource = dt;
        }
    }
}
